﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Database;

namespace Business
{
      public class QuanLyPhongHoc
    {
         TrungTamEntities trungtam;
         public QuanLyPhongHoc()
        {
            trungtam = new TrungTamEntities();
        }
        public List<PhongHoc> LayDanhSachPhong()
        {
            var list= (from p in trungtam.PhongHocs select p).ToList();
            return list;
        }

        public PhongHoc LayPhongTheoMa(String MaPhong)
        {
            var phonghoc = (from p in trungtam.PhongHocs
                            where p.MaPhong.Equals(MaPhong)
                           select p).First();
            return phonghoc;
        }
        public bool ThemPhong(PhongHoc phong)
        {
            try
            {
                trungtam.AddToPhongHocs(phong);
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool XoaPhong(String MaPhong)
        {
            var phong = (from p in trungtam.PhongHocs
                            where p.MaPhong.Equals(MaPhong)
                           select p).First();
            try
            {
                trungtam.DeleteObject(phong);
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool SuaPhong(PhongHoc phong)
        {
            var phonghoc = (from p in trungtam.PhongHocs
                            where p.MaPhong.Equals(phong.MaPhong)
                           select p).First();
            
            try
            {
                trungtam.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
